﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Reflection;
using 抽象工厂模式.Models;
using 抽象工厂模式.Factory;

namespace 抽象工厂模式
{
    class Program
    {
        static void Main(string[] args)
        {

            //Test1();

            Test2();

            Console.ReadLine();
        }

        /// <summary>
        ///  抽象工厂模式，。提供一个创建一系列相关对象【eg：数据表对象】的接口 IFactory
        ///  但是 增加表对象 比较麻烦
        /// </summary>
        static void Test1()
        {
            User user = new User();
            Department department = new Department();

            List<IFactory> list = new List<IFactory>();

            IFactory factory = new SqlFactory();
            list.Add(factory);
            //同理可以创建 AccessFactory
            IFactory factory2 = new AccessFactory();
            list.Add(factory2);
            foreach (var item in list)
            {
                IUser iu = item.CreateUser();
                iu.insert(user);
                iu.GetUser(1);

                IDepartment ide = item.CreateDepartment();
                ide.insert(new Department());
                ide.GetDepartment(2);
            }
            Console.ReadLine();
        }


        /// <summary>
        /// 用简单工厂模式来改造，去除工厂接口，加一DataAccess类
        /// 并用反射+配置文件
        /// </summary>
        static void Test2()
        {
            //改为DataAccess后
            IUser iuser2 = DataAccess.CreateUser();
            iuser2.insert(new User());
            iuser2.GetUser(1);

            IDepartment ide2 = DataAccess.CreateDepartment();
            ide2.insert(new Department());
            ide2.GetDepartment(2);
        }

    }






   
}